home *** CD-ROM | disk | FTP | other *** search
/ Treccani Italiana Di Scienze Lettere Ed Arti / [Enciclopedia] Treccani Italiana di scienze lettere ed arti.iso / pc / data / xxi_appendice_dvd.swf / scripts / __Packages / CLoadingQueue.as < prev    next >
Text File  |  2007-11-08  |  5KB  |  132 lines

  1. class CLoadingQueue extends mx.events.EventDispatcher
  2. {
  3.    static var TYPE_MOVIECLIP = 0;
  4.    static var TYPE_XML = 1;
  5.    function CLoadingQueue(p_scope, p_slots)
  6.    {
  7.       super();
  8.       if(!p_scope)
  9.       {
  10.          p_scope = _root;
  11.       }
  12.       this._scope = p_scope;
  13.       this._queue = new Array();
  14.       this._isLoading = false;
  15.       this._usedSlots = 0;
  16.       this.setSlots(p_slots);
  17.    }
  18.    function setSlots(p_slots)
  19.    {
  20.       if(isNaN(p_slots) || p_slots < 1)
  21.       {
  22.          p_slots = 1;
  23.       }
  24.       this._maxSlots = p_slots;
  25.    }
  26.    function addMovie(p_mc, p_url, p_id, p_priority)
  27.    {
  28.       if(isNaN(p_priority))
  29.       {
  30.          p_priority = 5;
  31.       }
  32.       this._queue.push({type:CLoadingQueue.TYPE_MOVIECLIP,target:p_mc,url:p_url,isLoading:false,priority:p_priority,id:p_id});
  33.    }
  34.    function addXML(p_xml, p_url, p_id, p_priority)
  35.    {
  36.       if(isNaN(p_priority))
  37.       {
  38.          p_priority = 5;
  39.       }
  40.       this._queue.push({type:CLoadingQueue.TYPE_XML,target:p_xml,url:p_url,isLoading:false,priority:p_priority,id:p_id});
  41.    }
  42.    function start()
  43.    {
  44.       if(!this._isLoading)
  45.       {
  46.          this._isLoading = true;
  47.          this._scope.createEmptyMovieClip("LoadingQueueController",this._scope.getNextHighestDepth());
  48.          this._scope.LoadingQueueController.loadingInstance = this;
  49.          this._scope.LoadingQueueController.onEnterFrame = function()
  50.          {
  51.             this.loadingInstance.update();
  52.          };
  53.       }
  54.    }
  55.    function update()
  56.    {
  57.       if(this._isLoading)
  58.       {
  59.          if(this._queue.length > 0)
  60.          {
  61.             if(this._usedSlots < this._maxSlots)
  62.             {
  63.                var _loc6_ = undefined;
  64.                var _loc5_ = undefined;
  65.                var _loc2_ = 0;
  66.                while(_loc2_ < this._queue.length)
  67.                {
  68.                   if(!this._queue[_loc2_].isLoading && (_loc5_ == undefined || this._queue[_loc2_].priority < _loc5_))
  69.                   {
  70.                      _loc6_ = _loc2_;
  71.                      _loc5_ = this._queue[_loc2_].priority;
  72.                   }
  73.                   _loc2_ = _loc2_ + 1;
  74.                }
  75.                if(!isNaN(_loc6_))
  76.                {
  77.                   switch(this._queue[_loc6_].type)
  78.                   {
  79.                      case CLoadingQueue.TYPE_MOVIECLIP:
  80.                         this._queue[_loc6_].target.loadMovie(this._queue[_loc6_].url);
  81.                         break;
  82.                      case CLoadingQueue.TYPE_XML:
  83.                         this._queue[_loc6_].target.load(this._queue[_loc6_].url);
  84.                   }
  85.                   this._queue[_loc6_].isLoading = true;
  86.                   this._usedSlots = this._usedSlots + 1;
  87.                }
  88.             }
  89.             var _loc3_ = undefined;
  90.             var _loc8_ = undefined;
  91.             var _loc7_ = undefined;
  92.             var _loc4_ = undefined;
  93.             var _loc9_ = undefined;
  94.             _loc2_ = 0;
  95.             while(_loc2_ < this._queue.length)
  96.             {
  97.                if(this._queue[_loc2_].isLoading)
  98.                {
  99.                   _loc3_ = this._queue[_loc2_].target;
  100.                   _loc8_ = this._queue[_loc2_].id;
  101.                   _loc7_ = _loc3_.getBytesLoaded();
  102.                   _loc4_ = _loc3_.getBytesTotal();
  103.                   _loc9_ = this._queue[_loc2_].type == CLoadingQueue.TYPE_MOVIECLIP && _loc3_._width > 0 || this._queue[_loc2_].type == CLoadingQueue.TYPE_XML && _loc3_.loaded;
  104.                   if(_loc7_ >= _loc4_ && _loc4_ > 100 && _loc9_ || _loc3_ == undefined || _loc4_ == undefined)
  105.                   {
  106.                      this.dispatchEvent({type:"onLoadingQueueMessage",target:this,eventName:"loaded",eventArg:_loc8_});
  107.                      this._queue.splice(_loc2_,1);
  108.                      _loc2_ = _loc2_ - 1;
  109.                      this._usedSlots = this._usedSlots - 1;
  110.                   }
  111.                }
  112.                _loc2_ = _loc2_ + 1;
  113.             }
  114.          }
  115.          else
  116.          {
  117.             this.dispatchEvent({type:"onLoadingQueueMessage",target:this,eventName:"complete",eventArg:0});
  118.             this.stop();
  119.          }
  120.       }
  121.    }
  122.    function stop()
  123.    {
  124.       if(this._isLoading)
  125.       {
  126.          this.dispatchEvent({type:"onLoadingQueueMessage",target:this,eventName:"stopped",eventArg:0});
  127.          this._isLoading = false;
  128.          this._scope.LoadingQueueController.removeMovieClip();
  129.       }
  130.    }
  131. }
  132.